home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / scilab / tests / auto.tst < prev    next >
Text File  |  1999-09-16  |  4KB  |  178 lines

  1. // test conversion transfer <---> state-space
  2. // 1- coff inversion 
  3.  s=poly(0,'s'); a=[1 2 3;4 5 6;7 8 9];
  4.  [num,den]=coff(a,'s');h1=num/den;h2=(s*eye-a)**(-1);
  5.  e=h1-h2;if norm(coeff(e(2)))>5000*%eps then pause,end
  6. // 2-test de tf2ss et ss2tf
  7.  n=[1+s   2+3*s+4*s**2        5; 0        1-s             s];
  8.  d=[1+3*s   5-s**3           s+1;1+s     1+s+s**2      3*s-1];
  9.  
  10.  h=syslin('c',n./d);
  11.  [n,d]=simp(n,d);if h<>tlist('r',n,d,'c') then pause,end
  12.  sl=tf2ss(h); e=h-ss2tf(sl);
  13.  if norm(coeff(e(2)))>100000*%eps then pause,end
  14.  
  15.  
  16. //
  17.   a = [0.8604043 , 0.0070020 , 0.6223373 , -1.356213 , -4.2301775
  18.        0.159714 ,  0.0857791 , -0.2367751 , 0.4958580 , 0.6398817
  19.       -4.3054931 , -0.0365878 , 2.1784911 , 0.0314793 , 2.3728994
  20.       -3.7115779 , -0.5370809 , 2.4291716 , -0.6352663 , 2.6972781
  21.        6.3580966 , 0.1377712 , -4.0461243 , -0.5192899 , -4.0394083];
  22.   b = [-0.0532544 , -0.1494083 , -0.0098619
  23.        -0.0355030 , -0.0162722 , 0.1045365
  24.        -0.1301775 , 0.1736686 , -0.0611440
  25.         0.1834320 , 0.1757396 , -0.5956607
  26.         0.1775148 , -0.1186391 , 0.1439842];
  27.   c = [2 , 7 , -2 , 5 , 1
  28.        0 , -1 , 3 , 0 , 2];
  29.   d = [1 , 0 , 0
  30.        0 , 0 , 0];
  31.  
  32. sl=syslin('c',a,b,c);
  33. if sl<>tlist('lss',a,b,c,0*ones(2,3),0*ones(5,1),'c') then pause,end
  34. //
  35. eps=sqrt(%eps);
  36. if contr(a,b,eps)<>4 then pause,end
  37. if contr(a',c',eps)<>3 then pause,end
  38. spec(a);
  39. xbasc();xselect();
  40. plzr(sl)
  41. //
  42. slc=contrss(sl,eps);ssprint(slc)
  43. slo=obsvss(sl,eps);ssprint(slo)
  44. slm=minss(sl,eps);ssprint(slm)
  45. //
  46. hm=ss2tf(slm);
  47. h=ss2tf(sl);
  48. hh=c*(s*eye-a)**(-1)*b + 0*ones(2,3);
  49. hh=hh-h;
  50. if norm(coeff(hh(2))) > 1.e-5 then pause,end
  51. [num,den]=coff(a,'s');
  52. hh=c*real(num)*b/real(den) + 0*ones(2,3);
  53. hh=hh-h;
  54. if norm(coeff(hh(2))) > 1.e-5 then pause,end
  55. slh=tf2ss(hm)       //was tf2ss(h)
  56. //
  57. u=eye(3,60);
  58. xbasc();
  59. halt();
  60. plot2d1("enn",1,flts(u,dscr(slh,0.3))');
  61. plot2d1("enn",1,flts(u,dscr(sl,0.3))',[-3,-4],"101")
  62.  
  63. //csim  flts
  64. //definition
  65. ti=2.7;k=0.87;td=0.69;n=200;
  66.  
  67. a=[0 0 0 0 0 -1/ti
  68.    0 -n/td 0 0 0 n/td
  69.    k n -1 0 0 -k-n
  70.    0 0 1 -1 0 0
  71.    0 0 0 1 -1 0
  72.    0 0 0 0 1 -1];
  73.  
  74. b=[1/ti;0;k;0;0;0];
  75.  
  76. c=[0 0 0 0 0 1];
  77. tech=0.2;t=0:tech:15; //
  78. deff('[y]=u(t)','if t=0 then y=0;else y=1,end') //step
  79.  
  80. // avec csim
  81. if type(csim)<>13 then comp(csim);end
  82. sl=syslin('c',a,b,c);
  83. //comparison 
  84. // csim
  85. xbasc(xget("window"));
  86. plot2d(t',csim(u,t,sl)')
  87. plot2d(t',csim('ech',t,sl)',-2,"001")
  88. //exact discretization
  89. sld=dscr(sl,tech);
  90. plot2d(t',flts(ones(t),sld)',-3,"001")
  91. //
  92. //impulse responses
  93. //
  94. halt();xbasc();
  95. plot2d(t',csim('imp',t,sl)')
  96. //discretization
  97. plot2d(t',flts(eye(t)/tech,sld)',-2,"001");
  98. //fin
  99. halt();xbasc();
  100. //test bode - black et nyquist
  101.  s=poly(0,'s')
  102. // n=poly(1,'s','c'); d=real(poly([5+15*%i,5-15*%i],'s'))
  103.  n=1+s;d=1+2*s;
  104.  h=syslin('c',n,d)
  105.  sl=tf2ss(h);
  106.  sld=dscr(sl,0.01);
  107.  hd=ss2tf(sld);
  108. [w,rf]=repfreq(h,0.01,100);
  109. //
  110. //transfer
  111.  bode(h,0.01,100);
  112. halt();xbasc();
  113.  bode(h,0.01,100,0.01)
  114. halt();xbasc();
  115.  bode(sl,0.01,100);
  116. halt();xbasc();
  117.  bode(sl,0.01,100,0.01)
  118. halt();xbasc();
  119. //
  120.  bode(w,rf)
  121. halt();xbasc();
  122.  bode(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)))
  123. halt();xbasc();
  124. //
  125. //transfer
  126.  bode(sld,0.001,1)
  127. // bode(sld,0.001,1,0.01)
  128. //
  129. halt();xbasc();
  130. // bode(hd,0.001,1)
  131.  bode(hd,0.001,1,0.01)
  132. //
  133. //
  134. //nyquist
  135. //
  136. halt();xbasc();
  137. nyquist(h,0.01,100); nyquist(h,0.01,100,0.01);
  138. halt();xbasc();
  139. nyquist(sl,0.01,100); nyquist(sl,0.01,100,0.01);
  140. halt();xbasc();
  141. nyquist(w,rf);
  142. nyquist(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)));
  143. //
  144. //nyquist(sld,0.001,1);nyquist(sld,0.001,1,0.01);
  145. halt();xbasc();
  146. //nyquist(hd,0.001,1);nyquist(hd,0.001,1,0.01);
  147. halt();xbasc();
  148. //
  149. //black
  150. //
  151.  
  152. black(h,0.01,100); black(h,0.01,100,0.01);
  153. halt();xbasc();
  154. black(sl,0.01,100); black(sl,0.01,100,0.01);
  155. halt();xbasc();
  156. black(w,rf);
  157. halt();xbasc();
  158. black(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)));
  159. //
  160. halt();xbasc();
  161. black(sld,0.001,1);black(sld,0.001,1,0.01);
  162. halt();xbasc();
  163. black(hd,0.001,1);black(hd,0.001,1,0.01);
  164. halt();xbasc();
  165. //
  166. //test  dscr
  167. slc=syslin('c',[0 1;0 0],[0;0],[1,0]);qc=[0 0;0 0.1]
  168. qd=ones(2,2)./[30000 2000;2000 100];
  169. sld=syslin(0.1,[1 0.1;0 1],[0;0],[1 0]);
  170. [s1]=dscr(slc,0.1);
  171. if norm(s1(2)-sld(2))>10*%eps then pause,end
  172. if norm(s1(3)-sld(3))>10*%eps then pause,end
  173. [s1,r]=dscr(slc,0.1,qc);
  174. if norm(s1(2)-sld(2))>10*%eps then pause,end
  175. if norm(s1(3)-sld(3))>10*%eps then pause,end
  176. if norm(r-qd)>10*%eps then pause,end
  177.  
  178.